package com.ezandroid.alphago.engine;

/**
 * Holds zero-indexed game position coordinates
 * <p>
 * (i.e. 0-8, 0-12, or 0-18, not pixel offsets)
 * Coordinate of -1 used to indicate stone is off of the board
 * </p>
 */
public class Intersection implements Cloneable {

    public int x;
    public int y;

    public Intersection(int x, int y) {
        if (x < -1 || 19 < x || y < -1 || 19 < y) {
            throw new IndexOutOfBoundsException("Invalid Intersection parameters.");
        }
        this.x = x;
        this.y = y;
    }

    @Override
    protected Intersection clone() throws CloneNotSupportedException {
        Intersection clone = (Intersection) super.clone();
        return clone;
    }

    @Override
    public boolean equals(Object other) {
        return !(other == null || this.getClass() != other.getClass())
                && (x == ((Intersection) other).x && y == ((Intersection) other).y);
    }

    @Override
    public int hashCode() { return ((Integer) (x + 19 * y)).hashCode(); }

    @Override
    public String toString() {
        return "(" + x + ", " + y + ')';
    }
}
